﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ChequeManagement.BLL
{
    /// <summary>
    /// This Class Includes Data Member, Method 
    /// </summary>
    /// <Field>this field name is "dalCC" and type is DAL.DALChequeCategory and use this field on methods</Field>
    /// <Method>this class includes some method for add,edit,getall,remove data</Method>
    public class BLLChequeCategoryFactory : BaseFactory
    {

        #region Fields
        private ChequeManagement.DAL.DALChequeCategory dataObject = null;
        DAL.DALChequeCategory dalCC = new DAL.DALChequeCategory();
        DataTable dt = new DataTable();
        #endregion

        #region Methods
        /// <summary>
        /// This method get a object that type is ChequeManagement.BLL.BLLChequeCategory and check this object is valid or not valid if object is not valid throw a exception
        /// else if object is valid create a instance of DAL.DALChequeCategory class and call Insert method and set parameter
        /// </summary>
        /// <param name="chequeCategoryObject" Type="ChequeManagement.BLL.BLLChequeCategory"></param>
        /// <return>this type is void and Do not return</return>
        
        public BLLChequeCategoryFactory()
            : base("ChequeCategory")
        {
            dataObject = (ChequeManagement.DAL.DALChequeCategory)(base.DataAccessLayer);
        }
        public void Add(ChequeManagement.BLL.BLLChequeCategory chequeCategoryObject)
        {
          
                if (chequeCategoryObject.IsValid() == false)
                    throw (new ChequeManagement.Validation.InvalidBusinessObjectException(chequeCategoryObject.Errors));
                dalCC.Insert(chequeCategoryObject);
           
           
        }

        /// <summary>
        ///This method get a object that type is ChequeManagement.BLL.BLLChequeCategory and a object that type is int
        ///this method create a instance of  ChequeManagement.BLL.BLLChequeCategory that name is "chequeCategory" and set targetChequeCategoryID on GetByKey method
        ///if chequeCategoryObject parameter is IsValid this method call dalCC that type is DAL.DALChequeCategory and call Update method and set parameter 
        ///else if chequeCategoryObject parameter not is IsValid throw exception
        /// </summary>
        /// <param name="chequeCategoryObject" Type="ChequeManagement.BLL.BLLChequeCategory"></param>
        /// <param name="targetChequeCategoryID" Type="int"></param>
        /// <GetByKey method>this method declare on this page and call FetchByKey method on DAL layer and set parameter</GetByKey method>
        /// <return>this type is void and Do not return</return>
        public void Edit(ChequeManagement.BLL.BLLChequeCategory chequeCategoryObject, int targetChequeCategoryID)
        {
            try
            {
                if (chequeCategoryObject.IsValid() == false)
                    throw (new ChequeManagement.Validation.InvalidBusinessObjectException(chequeCategoryObject.Errors));

                dataObject.Update(chequeCategoryObject, targetChequeCategoryID);
            }

            catch (Exception ex)
            {
                throw (ex);
            }
        }
        
        /// <summary>
        /// This method have a parameter that type is DataTable
        /// and call dalCC that type is DAL.DALChequeCategory and call FetchAll method and set parameter for select all data 
        /// </summary>
        /// <param name="dataTable" Type="DataTable"></param>
        /// <return>this type is void and Do not return but parameter is DataTable and result return into this DataTable</return>
        public void GetAll(DataTable dataTable)
        {
            try
            {
                dalCC.FetchAll(dataTable);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method not have parameter
        /// and call dalCC that type is DAL.DALChequeCategory and call FetchAll method for select all data
        /// </summary>
        /// <returns>this method select all data and result return into List<> that type is BLL.BLLChequeCategory</returns>
        public List<BLL.BLLChequeCategory> GetAll()
        {
            try
            {
                return (dalCC.FetchAll());
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have parameters
        /// and call dalCC that type is DAL.DALChequeCategory and call FetchByField method and set parameters
        /// the filedname parameter select field name on select table and vlaue parameter select value that select field name and result return into dataTable parameter 
        /// </summary>
        /// <param name="fieldName" Type="ChequeManagement.BLL.BLLChequeCategory.ChequeCategoryField"></param>
        /// <param name="value" Type="object"></param>
        /// <param name="dataTable" Type="ref DataTable"></param>
        /// <return>this type is void and Do not return but parameter is DataTable and result return into this DataTable</return>
        public void GetByField(ChequeManagement.BLL.BLLChequeCategory.ChequeCategoryField fieldName, object value, ref DataTable dataTable)
        {
            try
            {
                dalCC.FetchByField(fieldName.ToString(), value, dataTable);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have parameters
        /// and call dalCC that type is DAL.DALChequeCategory and call FetchByField method and set parameters
        /// the filedname parameter select field name on select table and vlaue parameter select value that select field name
        /// </summary>
        /// <param name="fieldName" Type="ChequeManagement.BLL.BLLChequeCategory.ChequeCategoryField"></param>
        /// <param name="value" Type="object"></param>
        /// <returns>this method select data and result return into List<> that type is BLL.BLLChequeCategory</returns>
        public List<BLL.BLLChequeCategory> GetByField(ChequeManagement.BLL.BLLChequeCategory.ChequeCategoryField fieldName, object value)
        {
            try
            {
                return (dalCC.FetchByField(fieldName.ToString(), value));
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have parameter
        /// and call dalCC that type is DAL.DALChequeCategory and call FetchAllByCondition method and set parameters
        /// select data by this condition
        /// </summary>
        /// <param name="condition" Type="string"></param>
        /// <param name="dataTable" Type=" ref DataTable"></param>
        /// <return>this type is void and Do not return but parameter is DataTable and result return into this DataTable</return>
        public void GetAllByCondition(string condition, ref DataTable dataTable)
        {
            try
            {
                dalCC.FetchAllByCondition(condition, dataTable);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have parameter
        /// and call dalCC that type is DAL.DALChequeCategory and call FetchByKey method and set parameters
        /// select data by targetChequeCategoryID
        /// </summary>
        /// <param name="targetChequeCategoryID" Type="int"></param>
        /// <returns>object that type is BLL.BLLChequeCategory </returns>
        public BLL.BLLChequeCategory GetByKey(int targetChequeCategoryID)
        {
            try
            {
                return (dalCC.FetchByKey(targetChequeCategoryID));
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have parameter
        /// and call dalCC that type is DAL.DALChequeCategory and call Delete method and set parameters
        /// </summary>
        /// <param name="targetChequeCategoryID" Type="int"></param>
        /// <return>this type is void and Do not return</return>
        public void Remove(int targetChequeCategoryID)
        {
            try
            {
                dalCC.Delete(targetChequeCategoryID);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have parameter
        /// and call dalCC that type is DAL.DALChequeCategory and call Delete method and set parameters
        /// remove field from table by this fieldName that value is this value
        /// </summary>
        /// <param name="fieldName" Type="ChequeManagement.BLL.BLLChequeCategory.ChequeCategoryField"></param>
        /// <param name="value" Type="object"></param>
        /// <return>this type is void and Do not return</return>
        public void Remove(ChequeManagement.BLL.BLLChequeCategory.ChequeCategoryField fieldName, object value)
        {
            try
            {
                dalCC.Delete(fieldName.ToString(), value);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        #endregion
    }
}
